<script type="text/javascript">
	function SwapTab(name, cls_show, cls_hide, cnt, cur) {
		for (i = 1; i <= cnt; i++) {
			if (i == cur) {
				$('#div_' + name + '_' + i).show();
				$('#tab_' + name + '_' + i).addClass(cls_show);
				$('#tab_' + name + '_' + i).removeClass(cls_hide);
			} else {
				$('#div_' + name + '_' + i).hide();
				$('#tab_' + name + '_' + i).removeClass(cls_show);
				$('#tab_' + name + '_' + i).addClass(cls_hide);
			}
		}
	}

	function att_show(img_src) {
		$(".icon").remove();

		var num = $('#fsUploadProgress').find("li").size();

		small_img_src = "<?php echo Configure::read('admin_config.mainDomain'); ?>"
				+ img_src;

		var temp_float = new String;
		temp_float += '<li id="attachment_' + num + '"><div class="img-wrap">';
		temp_float += '<a href="javascript:;" onclick="javascript:att_cancel('
				+ num + ')" class="on">';
		temp_float += '<img src="'+small_img_src+'" small_src="'+img_src+'"src="'+img_src+'" width="80">';
		temp_float += '<div class="icon"></div>';
		temp_float += '</a></div></li>';
		$('#fsUploadProgress').append(temp_float);

		var img_src = $("#attachment_" + num).find("img").attr("src");
		window.top.$("#thumb_preview").attr("src", img_src);

		var small_img_src = $("#attachment_" + num).find("img").attr(
				"small_src");
		window.top.$("#" + img_src_id).val(small_img_src);
	}

	var img_src_id = '<?php echo $id;?>';

	function att_cancel(num) {
		if ($("#attachment_" + num).find("a").hasClass("on")) {
			$('#fsUploadProgress').find(".on").removeClass("on");
			$('#fsUploadProgress').find(".icon").remove();

			//window.top.$("#thumb_preview").attr("src","/img/icon/upload-pic.png");
			//window.top.$("#" + img_src_id).val('');
		} else {
			$('#fsUploadProgress').find(".on").removeClass("on");
			$('#fsUploadProgress').find(".icon").remove();

			$("#attachment_" + num).find("a").addClass("on");
			$("#attachment_" + num).find("a")
					.append('<div class="icon"></div>');

			//var img_src = $("#attachment_" + num).find("img").attr("src");
			//window.top.$("#thumb_preview").attr("src", img_src);

			//var small_img_src = $("#attachment_" + num).find("img").attr("small_src");
			//window.top.$("#" + img_src_id).val(small_img_src);
		}
	}

	function ajaxFileUpload() {
		$.ajaxFileUpload({
			url : '/Attachment/<?php echo $url;?>/',
			secureuri : false,
			fileElementId : 'image',
			dataType : 'json',
			data : {
				name : 'logan',
				id : 'id'
			},
			success : function(data, status) {
				if (typeof (data.error) != 'undefined') {
					if (data.error != '') {
						notice_error(data.error);
					} else {
						att_show(data.msg);
					}
				}
			},
			error : function(data, status, e) {
				notice_error(e);
			}
		})

		return false;
	}
</script>
<body>
	<div class="pad-10">
		<div class="col-tab">
			<ul class="tabBut cu-li">
				<li id="tab_swf_1" class="on" onclick="SwapTab('swf','on','',5,1);">上传附件</li>
				<li id="tab_swf_2" onclick="SwapTab('swf','on','',5,2);">网络文件</li>
				<li id="tab_swf_3"
					onclick="SwapTab('swf','on','',5,3);set_iframe('album_list','/Attachment/albumload/<?php echo $id;?>/');">图库</li>
				<li id="tab_swf_4"
					onclick="SwapTab('swf','on','',5,4);set_iframe('album_dir','/Attachment/albumdir/<?php echo $id;?>/');">目录浏览</li>
			</ul>
			<div id="div_swf_1" class="content pad-10 ">
				<div>
					<div class="addnew" id="addnew">
						<form name="form" action="" method="POST"
							enctype="multipart/form-data">
							<input type="hidden" name="type" value="<?php echo $type;?>">
							<input type="hidden" name="id" value="<?php echo $id;?>">
							<input id="image" type="file" size="45" name="image"
								class="input"> <input type="button" id="btupload"
								value="开始上传" onclick="return ajaxFileUpload();" />
						</form>
					</div>
					<div class="onShow">
						最多上传 <font color="red"> 1 </font>个附件,单文件最大 <font color="red">2MB</font>
					</div>
					<div class="bk3"></div>
					<div class="onShow">
						支持 <font style="font-family: Arial, Helvetica, sans-serif">jpg，jpeg，bmp，gif，png</font>
						格式。
					</div>
					<div class="bk3"></div>
					<div class="onShow">
						<input type="checkbox" id="watermark_enable" value="1">
						是否添加水印
					</div>
				</div>
				<div class="bk10"></div>
				<fieldset class="blue pad-10" id="swfupload">
					<legend>列表</legend>
					<ul class="attachment-list" id="fsUploadProgress">
					</ul>

				</fieldset>
			</div>
			<div id="div_swf_2" class="contentList pad-10 hidden">
				<div class="bk10"></div>
				请输入网络地址
				<div class="bk3"></div>
				<input type="text" name="info[filename]" class="input-text" value=""
					style="width: 350px;" onblur="addonlinefile(this)">
				<div class="bk10"></div>
			</div>
			<div id="div_swf_3" class="contentList pad-10 hidden">
				<ul class="attachment-list">
					<iframe name="album-list" src="#" frameborder="false"
						scrolling="no" style="overflow-x: hidden; border: none"
						width="100%" height="345" allowtransparency="true" id="album_list"></iframe>
				</ul>
			</div>
			<div id="div_swf_4" class="contentList pad-10 hidden">
				<ul class="attachment-list">
					<iframe name="album-dir" src="#" frameborder="false"
						scrolling="auto" style="overflow-x: hidden; border: none"
						width="100%" height="330" allowtransparency="true" id="album_dir"></iframe>
				</ul>
			</div>
		</div>
	</div>
</body>